import { defineStore } from "pinia";
// userInfo 存储对象的名称
export const routeHistory: any = defineStore("routeHistory", {
  // state是一个函数，返回一个对象
  state: () => {
    return {
      dynamicTags: [],
    };
  },
  actions: {
    // 删除当前路由
    delItem(index: any) {
      let newDynamicTags = [...this.dynamicTags];
      newDynamicTags.splice(index, 1);
      this.dynamicTags = newDynamicTags;
    },
    // 路由跳转历史
    linkPush(item: any) {
      // 检查是否已经存在相同的 routePath
      const existingIndex = this.dynamicTags.findIndex(
        (tag) => tag.routePath === item.routePath
      );
      // 如果存在，则不执行添加操作
      if (existingIndex !== -1) {
        return;
      }
      // 否则，执行添加操作
      const newDynamicTags = [ ...this.dynamicTags,item];
      this.dynamicTags = newDynamicTags;
    },
  },
});
// 使用说明 import { storeToRefs } from 'pinia'  import { useUser } from "@/store/modules/userInfo" const userStore = useUser()   const { userName, avatar } = storeToRefs(userStore) userStore.changeUserName("New UserName")
